//
//  EditViewController.m
//  tmp2TableView
//
//  Created by hh on 15/11/30.
//  Copyright © 2015年 hh. All rights reserved.
//

#import "EditViewController.h"



@interface EditViewController ()
{
    UITextField *tfName;
    UITextField *tfTel;
}
@end

@implementation EditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    tfName = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16, 44)];
    tfTel = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16, 44)];
    tfName.text = self.name;
    tfTel.text = self.tel;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save:)];
}

- (void)save:(UIBarButtonItem *)barItem
{
    [self.delegate editFinishedWithName:tfName.text tel:tfTel.text];
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    [cell.contentView addSubview:indexPath.section == 0 ? tfName : tfTel];
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @[@"姓名：", @"电话："][section];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
